package bb.lanxing.lib.devices.ble.ble.characteristic.cadence;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import bb.lanxing.lib.devices.ble.ble.base.BaseBleCharacteristic;
import bb.lanxing.lib.devices.ble.ble.base.BaseBleService;
import bb.lanxing.lib.devices.core.provider.DataNotifier;
import java.util.UUID;
import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;

public final class CscMeasurementCharacteristics extends BaseBleCharacteristic {
    final private static String TAG = "CscMeasurementCharacteristics";
    public CscMeasurementCharacteristics(BaseBleService bleService) {
        super(bleService);
        Intrinsics.checkNotNullParameter(bleService, "bleService");
    }

    @Override
    public UUID targetUUID() {
        UUID fromString = UUID.fromString("00002A5B-0000-1000-8000-00805f9b34fb");
        Intrinsics.checkNotNullExpressionValue(fromString, "fromString(BLEAttributes.BLE_CADENCE_MEASUREMENT)");
        return fromString;
    }

    @Override
    public void onValueUpdate(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
        int i;
        int i2;
        int i3;
        int i4;
        int i5;
        int i6;
        Intrinsics.checkNotNullParameter(gatt, "gatt");
        Intrinsics.checkNotNullParameter(characteristic, "characteristic");
        Integer intValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
        int i7 = 1;
        if ((intValue & 1) > 0) {
            Integer intValue2 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, 1);
            Intrinsics.checkNotNullExpressionValue(intValue2, "characteristic.getIntVal…ic.FORMAT_UINT32, offset)");
            i = intValue2;
            Integer intValue3 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 5);
            Intrinsics.checkNotNullExpressionValue(intValue3, "characteristic.getIntVal…ic.FORMAT_UINT16, offset)");
            i2 = intValue3;
            i7 = 7;
        } else {
            i = -1;
            i2 = -1;
        }
        if ((intValue & 2) > 0) {
            Integer intValue4 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, i7);
            Intrinsics.checkNotNullExpressionValue(intValue4, "characteristic.getIntVal…ic.FORMAT_UINT16, offset)");
            i4 = intValue4;
            int i8 = i7 + 2;
            Integer intValue5 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, i8);
            Intrinsics.checkNotNullExpressionValue(intValue5, "characteristic.getIntVal…ic.FORMAT_UINT16, offset)");
            i3 = intValue5;
            i7 = i8 + 2;
        } else {
            i3 = -1;
            i4 = -1;
        }
        if ((intValue & 4) > 0) {
            Integer intValue6 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, i7);
            Intrinsics.checkNotNullExpressionValue(intValue6, "characteristic.getIntVal…ic.FORMAT_UINT32, offset)");
            i5 = intValue6;
            Integer intValue7 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, i7 + 4);
            Intrinsics.checkNotNullExpressionValue(intValue7, "characteristic.getIntVal…ic.FORMAT_SINT16, offset)");
            i6 = intValue7;
        } else {
            i5 = -1;
            i6 = -1;
        }
        Log.d(TAG, "CscMeasurementChara" + "onCadenceData: sumWheel = " + i + ", wheelTime = " + i2 + ", sumCadence = " + i4 + ", cadenceTime = " + i3 + ", pressure = " + i5 + ", temperature = " + i6);
        if (i != -1 || i2 != -1) {
            DataNotifier.notifyRawSpeedCadenceData(getBleService().getDevice().getType(), i2, i);
        }
        if (i4 != -1 || i3 != -1) {
            DataNotifier.notifyRawCadenceData(getBleService().getDevice().getType(), i3, i4);
        }
        if (i5 != -1) {
            DataNotifier.notifyPressureData(getBleService().getDevice().getType(), i5);
        }
        if (i6 != -1) {
            DataNotifier.notifyTemperatureData(getBleService().getDevice().getType(), i6);
        }
    }
}
